﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="CRM.Web.Admin.Page.ArticleInfo.Edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="/Content/jquery/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="/Content/jquery/jquery-1.4.1.js" type="text/javascript"></script>
    <link href="/Content/jquery/validation/validation.css" rel="stylesheet" type="text/css" />
    <script src="/Content/jquery/validation/validation.js" type="text/javascript"></script>
    <script src="/Content/jquery/artDialog/jquery.artDialog.source.js?skin=default" type="text/javascript"></script>
    <script src="/Content/jquery/artDialog/plugins/iframeTools.source.js?skin=default"
        type="text/javascript"></script>
    <script src="/Content/jquery/query_url.js" type="text/javascript"></script>
    <script src="/Content/jquery/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Content/jquery/kindeditor/kindeditor.js" type="text/javascript"></script>
    <script src="/Content/jquery/uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
    <script src="/Content/jquery/uploadify/swfobject.js" type="text/javascript"></script>
    <script type="text/javascript">

        var editor;

        //页面呈现后再次默认初始化
        window.onload = function () {
            //默认初始化
            _cnblogs_yixian_edit._initFunc();

            //默认加载第一条
            _cnblogs_yixian_edit._getSingleFunc();
        }

        $(document).ready(function () {
            //文章名称
            $('#Title').blur(function () {
                ValidationInput($(this),
{ s: '', e: '必填项', showSuccess: false },
{ min: 1, max: 100, e: '长度在1-100的指定范围', s: '', showSuccess: true },
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            //图片
            $('#Image').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            $('#Image_file').uploadify({
                'uploader': '/Content/jquery/uploadify/uploadify.swf',
                'script': '/Ajax/ArticleInfoAjax.ashx?action=FileUploadFunc',
                'cancelImg': '/Content/jquery/uploadify/cancel.png',
                'fileExt': '*.gif;*.jpeg;*.jpg;*.png',
                'fileDesc': '请选择jpg,jpeg,gif,png,bmp图片',
                'sizeLimit': 1024 * 1024 * 5,
                'multi': true,
                'auto': true,
                'onSelectOnce': function (event, data) {
                },
                'onComplete': function (event, queueID, fileObj, response, data) {
                    $('#Image').val(response).trigger('blur');
                    $('#Image_image').attr("src", response);
                    //$.dialog.alert('上传成功！' + response);
                },
                'onError': function (event, queueID, fileObj, errorObj) {
                    $.dialog.alert('上传插件出现异常！');
                }
            });
            //是否最新
            $('#IsNew').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            //是否置顶
            $('#IsTop').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            //文章内容
            $('#ArticleContent').blur(function () {
                ValidationInput($(this),
undefined,
undefined,
undefined
);
            }).focus(function () {
                ClearErrorMessage($(this));
            });
            KindEditor.ready(function (K) {
                editor = K.create('#ArticleContent', {
                    resizeType: 1,
                    allowPreviewEmoticons: false,
                    allowImageUpload: true,
                    items: [
'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
'insertunorderedlist', '|', 'emoticons', 'image', 'link', '|', 'source'],
                    afterBlur: function () {
                        $('#ArticleContent').val(editor.text()).trigger('blur');
                    },
                    afterFocus: function () {
                        ClearErrorMessage($('#ArticleContent'));
                    }
                });
            });

        });

        var _cnblogs_yixian_edit = {

            //单一实体
            _single: {},

            //主键ID
            _id: "",

            //初始化函数
            _initFunc: function () {
                _cnblogs_yixian_edit._id = $.query.get("ArticleId");
            },

            //获取单一实体
            _getSingleFunc: function () {
                $.ajax({
                    type: "post",
                    data: {
                        action: "SingleFunc",
                        ArticleId: _cnblogs_yixian_edit._id
                    },
                    url: "/Ajax/ArticleInfoAjax.ashx",
                    beforeSend: function () {
                    },
                    success: function (data) {
                        if (data != "") {
                            var json = $.parseJSON(data);

                            _cnblogs_yixian_edit._single = json;

                            $('#Title').val(json.Title);
                            $('#Image_image').attr("src", json.Image);
                            $('#Image').val(json.Image);
                            $("#IsNew").attr("checked", json.IsNew);
                            //                            $('#IsNew').val(json.IsNew);
                            $('#IsTop').attr("checked", json.IsTop);
                            $('#ArticleContent').val(json.ArticleContent);
                            editor.html($('#ArticleContent').val());

                        } else {
                            $.dialog.alert("获取数据失败！");
                        }
                    },
                    complete: function () {
                    },
                    error: function () {
                        $.dialog.alert("获取数据异常！");
                    }
                });
            },

            //提交表单
            _submitFunc: function ($this) {
                var load = "";
                var isSuccess = true;

                //需要验证的数组
                var validationArray = [
                  { Title: "" },
                                  { Image: "" },
                                  { IsNew: "" },
                                  { IsTop: "" },
                                  { ArticleContent: "" }
                ];

                //可空判断
                var result = SubmitForm(validationArray, true);

                //判断是否验证通过
                if (!result)
                    return isSuccess = false;

                //给实体赋值
                _cnblogs_yixian_edit._single.Title = $.trim($("#Title").val());
                _cnblogs_yixian_edit._single.Image = $.trim($("#Image").val());
                _cnblogs_yixian_edit._single.IsNew = false; //$("#IsNew").attr("checked");
                _cnblogs_yixian_edit._single.IsTop = false;// $("#IsTop").attr("checked");
                _cnblogs_yixian_edit._single.ArticleType = 1;

                _cnblogs_yixian_edit._single.ArticleContent = editor.html(); // $.trim($("#ArticleContent").val());

                $.ajax({
                    type: "post",
                    data: {
                        action: "EditFunc",
                        json: JSON.stringify(_cnblogs_yixian_edit._single)
                    },
                    url: "/Ajax/ArticleInfoAjax.ashx",
                    async: false,
                    beforeSend: function () {
                        load = $.dialog({ title: false, cancel: false });
                    },
                    success: function (data) {
                        if (data == "True") {
                            isSuccess = true;
                        } else {
                            isSuccess = false;
                        }
                    },
                    complete: function () {
                        load.close();
                    },
                    error: function () {
                        isSuccess = false;
                    }
                });
                return isSuccess;
            }
        };

    </script>
</head>
<body style="text-align: left; font-size: 12px">
    <table>
        <tr>
            <td>
                文章名称:
            </td>
            <td>
                <input type='text' id='Title' style="width:600px;" />
            </td>
        </tr>
        <tr>
            <td>
                图片:
            </td>
            <td>
                <img id='Image_image' width='80' height='80' />
                <input type='file' id='Image_file' />
                <input type='text' id='Image' style='visibility: collapse; width: 1px; height: 1px;
                    border: 0px; padding: 0px; margin: 0px' />
            </td>
        </tr>
        <tr style="display:none">
            <td>
                标志信息:
            </td>

            <td>
                <input type="checkbox" id='IsNew' /><label for="IsNew">是否最新</label>
                <input type="checkbox" id='IsTop' /><label for="IsTop">是否置顶</label>
            </td>            
        </tr>
        <tr>
            <td>
                文章内容:
            </td>
            <td>
                <textarea id='ArticleContent' style="width:800px;height:320px;"></textarea>
            </td>
        </tr>
    </table>
</body>
</html>
